home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / cd-sup / classact / examples / penmap / penmapexample.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  4KB  |  169 lines

  1. /*
  2.  * Example for ClassAct penmap.image
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <clib/alib_protos.h>
  7. #include <exec/types.h>
  8. #include <proto/dos.h>
  9. #include <proto/exec.h>
  10. #include <proto/intuition.h>
  11. #include <proto/graphics.h>
  12.  
  13. #include <intuition/imageclass.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <intuition/intuition.h>
  16.  
  17. #include <images/penmap.h>
  18.  
  19. struct ClassLibrary *PenMapBase;
  20.  
  21. struct Window    *win;
  22. struct Image     *image_object;
  23.  
  24. ULONG   image_object_palette[] =
  25. {
  26.    2,
  27.    0x00000000, 0x00000000, 0x00000000,
  28.    0xEEEEEEEE, 0xDDDDDDDD, 0x00000000
  29. };
  30.  
  31. UBYTE   happy_data[] =
  32. {
  33.    0,16, 0,14,
  34.    0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,
  35.    0,0,0,1,1,2,2,2,2,2,2,1,1,0,0,0,
  36.    0,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0,
  37.    0,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0,
  38.    0,1,2,2,2,1,1,2,2,1,1,2,2,2,1,0,
  39.    1,2,2,2,2,1,1,2,2,1,1,2,2,2,2,1,
  40.    1,2,2,2,2,1,1,2,2,1,1,2,2,2,2,1,
  41.    1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,
  42.    1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,
  43.    0,1,2,2,2,1,2,2,2,2,1,2,2,2,1,0,
  44.    0,1,2,2,2,2,1,1,1,1,2,2,2,2,1,0,
  45.    0,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0,
  46.    0,0,0,1,1,2,2,2,2,2,2,1,1,0,0,0,
  47.    0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0
  48. };
  49.  
  50. UBYTE   scared_data[] =
  51. {
  52.    0,16, 0,14,
  53.    0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,
  54.    0,0,0,1,1,2,2,2,2,2,2,1,1,0,0,0,
  55.    0,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0,
  56.    0,1,2,2,2,1,1,2,2,1,1,2,2,2,1,0,
  57.    0,1,2,2,1,2,2,2,2,2,2,1,2,2,1,0,
  58.    1,2,2,2,2,1,1,2,2,1,1,2,2,2,2,1,
  59.    1,2,2,2,2,1,1,2,2,1,1,2,2,2,2,1,
  60.    1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,
  61.    1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,
  62.    0,1,2,2,2,2,1,1,1,1,2,2,2,2,1,0,
  63.    0,1,2,2,2,1,1,1,1,1,1,2,2,2,1,0,
  64.    0,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0,
  65.    0,0,0,1,1,2,2,2,2,2,2,1,1,0,0,0,
  66.    0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0
  67. };
  68.  
  69.  
  70. /* Try opening the class library from a number of common places
  71.  */
  72. struct ClassLibrary *OpenClass (STRPTR name, ULONG version)
  73. {
  74.     struct ExecBase *SysBase = (*((struct ExecBase **) 4));
  75.     struct Library *retval;
  76.     UBYTE buffer[256];
  77.  
  78.     if ((retval = OpenLibrary (name, version)) == NULL)
  79.     {
  80.         sprintf (buffer, "SYS:Classes/%s", name);
  81.         if ((retval = OpenLibrary (buffer, version)) == NULL)
  82.         {
  83.             sprintf (buffer, "Classes/%s", name);
  84.             retval = OpenLibrary (buffer, version);
  85.         }
  86.     }
  87.     return (struct ClassLibrary *) retval;
  88. }
  89.  
  90. void main (void)
  91. {
  92.     struct IntuiMessage  *msg;
  93.     BOOL done = FALSE;
  94.  
  95.     win = OpenWindowTags (NULL,
  96.         WA_Flags,    WFLG_DEPTHGADGET | WFLG_DRAGBAR |
  97.                     WFLG_CLOSEGADGET | WFLG_SIZEGADGET,
  98.         WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE,
  99.         WA_InnerWidth,    40,
  100.         WA_InnerHeight,    30,
  101.         WA_MaxWidth,-1,
  102.         WA_MaxHeight,-1,
  103.         WA_Activate, TRUE,
  104.         WA_SmartRefresh, TRUE,
  105.         WA_Title, "ClassAct penmap.image Demo",
  106.         TAG_DONE);
  107.  
  108.     if (win)
  109.     {
  110.         if (PenMapBase = OpenClass("images/penmap.image", 40L))
  111.         {
  112.             image_object = (struct Image *)NewObject (NULL, "penmap.image",
  113.                 PENMAP_RenderData, happy_data,
  114.                 PENMAP_SelectData, scared_data,
  115.                 PENMAP_Palette, image_object_palette,
  116.                 PENMAP_Screen, win->WScreen,
  117.                 TAG_DONE);
  118.             if (image_object)
  119.             {
  120.                 SetAttrs(image_object,
  121.                     IA_Width,        win->Width - (win->BorderLeft + win->BorderRight + 10L),
  122.                     IA_Height,        win->Height - (win->BorderTop + win->BorderBottom + 10L),
  123.                     TAG_DONE);
  124.                 DrawImageState (win->RPort,
  125.                     image_object,
  126.                     win->BorderLeft + 5L,
  127.                     win->BorderTop + 5L,
  128.                     IDS_SELECTED, NULL);
  129.  
  130.                 while (!done)
  131.                 {
  132.                     WaitPort (win->UserPort);
  133.                     while (msg = (struct IntuiMessage *)GetMsg (win->UserPort))
  134.                     {
  135.                         if (msg->Class == IDCMP_CLOSEWINDOW)
  136.                             done = TRUE;
  137.                         else if (msg->Class == IDCMP_NEWSIZE)
  138.                         {
  139.                             SetAttrs(image_object,
  140.                                 IA_Width,        win->Width - (win->BorderLeft + win->BorderRight + 10L),
  141.                                 IA_Height,        win->Height - (win->BorderTop + win->BorderBottom + 10L),
  142.                                 TAG_DONE);
  143.                             SetAPen(win->RPort,0);
  144.                             RectFill(win->RPort,
  145.                                 win->BorderLeft,
  146.                                 win->BorderTop,
  147.                                 win->BorderLeft + win->Width - (win->BorderRight + win->BorderLeft + 1),
  148.                                 win->BorderTop + win->Height - (win->BorderTop + win->BorderBottom + 1));
  149.                             DrawImageState(win->RPort,
  150.                                 image_object,
  151.                                 win->BorderLeft + 5L,
  152.                                 win->BorderTop + 5L,
  153.                                 IDS_SELECTED,
  154.                                 NULL);
  155.                         }
  156.                         ReplyMsg ((struct Message *)msg);
  157.                     }
  158.                 }
  159.             }
  160.         }
  161.     }
  162.     if (image_object)
  163.         DisposeObject (image_object);
  164.     if (win)
  165.         CloseWindow (win);
  166.     if (PenMapBase)
  167.         CloseLibrary ((struct Library *)PenMapBase);
  168. }
  169.